package com.room.search.util;

import java.util.regex.Pattern;

/**
 * By   : ghd.bright
 * Time : 2022/1/10
 * Description: 正则校验工具类
 */
public class RegexCheckUtil {


    private static final String MOBILE_REGEX = "^1(3\\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\\d|9[0-35-9])\\d{8}$";
    private static final String EMAIL_REGEX = "^(\\w+([-.][A-Za-z0-9]+)*){3,18}@\\w+([-.][A-Za-z0-9]+)*\\.\\w+([-.][A-Za-z0-9]+)*$";

    /**
     * 手机号校验
     * @param mobile 手机
     */
    public static boolean checkMobile(String mobile) {
        if (mobile.length() != 11) {
            return false;
        }
        Pattern compile = Pattern.compile(MOBILE_REGEX, Pattern.MULTILINE);
        return compile.matcher(mobile).matches();
    }

    /**
     * 邮箱校验
     * @param email 邮箱
     */
    public static boolean checkEmail(String email) {
        Pattern compile = Pattern.compile(EMAIL_REGEX, Pattern.MULTILINE);
        return compile.matcher(email).matches();
    }
}
